﻿@using ZDSoft.LMS.Domain;
@model DeliveryForm
@{
    ViewBag.Title = "接单";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="@Url.Content("~/Content/Style/ViewPage.css")" rel="stylesheet" type="text/css" />
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; background-color: White;"
    align="center">
    <tr>
        <td class="mbg">
            <table cellspacing="0" cellpadding="0" width="100%" border="0" valign="top">
                <tr>
                    <td>
                        <table style="height: 23px;" cellspacing="0" cellpadding="0" width="120" background="@Url.Content("~/Content/Images/m_17.gif")"
                            border="0">
                            <tr>
                                <td>
                                    <span class="contentPageTitle">&nbsp;&gt;&gt; 回车报销</span>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="titleContentDivider" height="6">
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<p>
    @Html.ActionLink("返回列表", "Index")
</p>
<link href="@Url.Content("~/Content/Style/CreateTranportOrder.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
    var items = new Array();
    $(document).ready(function () {
        GenerateRow();
        RegisterEvents();
    });

    function RegisterEvents() {
        $("#tbFee").find("input").each(function () {
            this.onblur = function () {
                SetInputedValue(this);
            };
        });
        $("#tbFee").find("select").each(function () {
            this.onchange = function () {
                SetInputedValue(this);
            };
        });
    }

    function SetInputedValue(ctl) {
        var id = ctl.id;
        var val = ctl.value;
        var firstIdx = id.indexOf("_");
        var lastIdx = id.lastIndexOf("_");
        var rowIdx = id.substring(firstIdx + 1, lastIdx);
        var columnIdx = id.substring(lastIdx + 1);
        items[rowIdx][columnIdx] = val;
    }

    function SubmitForm() {
        $("#txtValues").val(items);
    }

    function GenerateNewArray() {
        items[items.length] = new Array('0', '0', '0', '0');
    }

    function GenerateRow() {
        GenerateNewArray();
        var rowsCount = $("#tbFee").find("tr").length;
        var trHtml = $("#trTemplate").html();
        if (rowsCount < 10) {
            trHtml = trHtml.replace("dis", "style='display:block'"); //当总行数小于9时，在最后
            //一行显示“添加按钮”否则“添加按钮”不出现
        }
        $("a[name='linkAdd']").css("display", "none"); //隐藏所有“添加按钮”
        while (trHtml.indexOf("_r") > 0) {
            var counter = "_" + (rowsCount - 2);
            trHtml = trHtml.replace("_r", counter);
        }
        var rowHtml = "<tr id='trTemplate_" + (rowsCount - 1) + "'>" + trHtml + "</tr>";
        $("#tbFee").append(rowHtml); //在列表的最后面添加一行
        RegisterEvents();
    }

    function DeleteRow(ctl) {
        if (confirm('真的删除吗?')) {
            var id = ctl.id;
            var firstIdx = id.indexOf("_");
            var rowIdx = id.substring(firstIdx + 1);
            items[rowIdx] = null;
            $("#trTemplate_" + rowIdx).remove();
        }
    }
</script>
<div>
    <table class="transportOrderTable" width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td width="70">
                送货人员：
            </td>
            <td colspan="2">
                @Html.DisplayFor(model => model.Transporter.UserName)
            </td>
            <td>
                运输车辆：
            </td>
            <td>
                @Html.DisplayFor(model => model.Vehicle.VehicleNumber)
            </td>
            <td>
                送货时间：
            </td>
            <td colspan="3">
                @Html.DisplayFor(model => model.DeliveryDate)
            </td>
        </tr>
        <tr>
            <td width="70">
                发站：
            </td>
            <td colspan="2">
                @Html.DisplayFor(model => model.TransportOrder.StartStation)
            </td>
            <td>
                到站：
            </td>
            <td colspan="5">
                @Html.DisplayFor(model => model.TransportOrder.Destionation)
            </td>
        </tr>
        <tr>
            <td rowspan="2">
                <span>收货人</span>
            </td>
            <td>
                <span>名称</span>
            </td>
            <td colspan="3">
                @Html.DisplayFor(model => model.TransportOrder.Receiver.Name)
            </td>
            <td>
                <span>电话</span>
            </td>
            <td>
                @Html.DisplayFor(model => model.TransportOrder.Receiver.Telephone)
            </td>
        </tr>
        <tr>
            <td>
                <span>地址</span>
            </td>
            <td>
                @Html.DisplayFor(model => model.TransportOrder.Receiver.Address)
            </td>
            <td>
                <span>邮编</span>
            </td>
            <td>
                @Html.DisplayFor(model => model.TransportOrder.Receiver.PostNumber)
            </td>
            <td>
                <span>E-mail</span>
            </td>
            <td>
                @Html.DisplayFor(model => model.TransportOrder.Receiver.Email)
            </td>
        </tr>
    </table>
</div>
<p>
    &nbsp;</p>
<div>
    <fieldset>
        <legend>报销清单</legend>
        <table cellpadding="0" cellspacing="0" class="dataGrid" id="tbFee">
            <tr>
                <th>
                    费用名称
                </th>
                <th>
                    费用类型
                </th>
                <th>
                    金额(RMB)
                </th>
                <th>
                    产生者
                </th>
                <th>
                    备注
                </th>
                <th width="100">
                    操作
                </th>
            </tr>
            <tr id="trTemplate" style="display: none;">
                <td>
                    <input id="itemName_r_0" />
                </td>
                <td>
                    @Html.DropDownList("typeId_r_1", new SelectList(ViewBag.BillingItemTypes, "ID", "Name"), "------请选择-----")
                </td>
                <td>
                    <input id="type_r_2" />
                </td>
                <td>
                    默认司机
                </td>
                <td>
                    <input id="remark_r_3" />
                </td>
                <td id="tdOperation">
                    <a href='#' name="linkDelete_r" id="linkDelete_r" onclick="DeleteRow(this)">删除</a><a
                        href='#' name="linkAdd" dis onclick='GenerateRow()'> 添加</a>
                </td>
            </tr>
        </table>
        @using (@Html.BeginForm("Create", "Billing"))
        { 
            <input name="txtValues" id="txtValues" />
            <p>
                <input value="保存" type="button" onclick="SubmitForm()" class="btn3" />
            </p>
        }
    </fieldset>
</div>
